package com.sunspring.zdcall.common;

import com.sunspring.zdcall.common.constant.ResponseConstant;
import com.sunspring.zdcall.common.constant.enums.WbResponseEnum;
import lombok.Data;

/**
 * 封装controller层通用返回格式
 * @Author WuLei
 * @Date 2018/11/26  20:04
 */
@Data
public class SimpleResponse {

    private int code;

    private String msg;

    private Object data;

    private SimpleResponse() {

    }

    private SimpleResponse(int code,String msg,Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private SimpleResponse(int code,String msg) {
        this.code = code;
        this.msg = msg;
    }


    /**
     * 成功，根据常量类ResponseConstant返回数据
     * @param responseConstant 通用常量类
     * @return SimpleResponse
     */
    public static SimpleResponse success(ResponseConstant responseConstant) {
        return new SimpleResponse(responseConstant.getCode(), responseConstant.getMsg());
    }

    /**
     * 通用成功返回,不带数据
     * @return SimpleResponse
     */
    public static SimpleResponse success() {
        return new SimpleResponse(1,"成功");
    }

    /**
     * 成功，带数据
     * @return SimpleResponse
     */
    public static SimpleResponse success(Object data) {
        return new SimpleResponse(1,"成功",data);
    }

    /**
     * 成功，自定义返回消息，不带数据
     * @return SimpleResponse
     */
    public static SimpleResponse success(String msg) {
        return new SimpleResponse(1,msg);
    }


    /**
     * 成功，自定义返回码和消息
     * @return SimpleResponse
     */
    public static SimpleResponse success(int code,String msg) {
        return new SimpleResponse(code,msg);
    }

    /**
     * 成功，自定义返回消息,带数据
     * @return SimpleResponse
     */
    public static SimpleResponse success(String msg,Object data) {
        return new SimpleResponse(1,msg,data);
    }

    /**
     * 失败，通用返回
     * @return SimpleResponse
     */
    public static SimpleResponse fail() {
        return new SimpleResponse(0,"失败");
    }

    /**
     * 失败，自定义返回消息
     * @return SimpleResponse
     */
    public static SimpleResponse fail(String msg) {
        return new SimpleResponse(0,msg);
    }

}
